package com.family.base.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.util.ValueStack;

/**
 * Action帮助类
 * @author kangx
 *
 */
public abstract class BaseAction extends ActionSupport 
	implements ModelDriven<Object>, RequestAware, SessionAware{

	private static final long serialVersionUID = -8033294652440520954L;
	protected Map<String, Object> request = new HashMap<String, Object>();
	protected Map<String, Object> session = new HashMap<String, Object>();
	
	protected ValueStack getValueStack(){
		ActionContext context = ActionContext.getContext();
		return context.getValueStack();
	}

	protected void setSessionAttribute(String name, Object value) {
		this.session.put(name, value);
	}

	protected Object getSessionAttribute(String name) {
		return this.session.get(name);
	}

	protected void setRequestAttribute(String name, Object value) {
		this.session.put(name, value);
	}

	protected Object getRequestAttribute(String name) {
		return this.session.get(name);
	}

	public Map<String, Object> getRequest() {
		return this.request;
	}

	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	public Map<String, Object> getSession() {
		return this.session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	

//	@SuppressWarnings("unchecked")
//	protected <T> T getSessionAttribute(String name, Class<T> clazz) {
//		Object value = getSessionAttribute(name);
//		if (value == null)
//			return null;
//		return (T) value;
//	}
//
//	@SuppressWarnings("unchecked")
//	protected <T> T getRequestAttribute(String name, Class<T> clazz) {
//		Object value = getRequestAttribute(name);
//		if (value == null)
//			return null;
//		return (T) value;
//	}


}
